#include <bits/stdc++.h>
using namespace std;

using ll = long long;
const int N = 1e3 + 10;
ll a[N], pre[N];
ll n, ret = LLONG_MAX;
vector<ll> v;

int main()
{
	cin >> n;
	for (int i = 1; i <= n; i++)
	{
		cin >> a[i];
		pre[i] = pre[i - 1] + a[i]; // 计算前缀和数组 
	}
	for (int r = 2; r <= n; r++)
		for (int l = 1; l < r; l++)
			v.push_back(pre[r] - pre[l]);
	sort(v.begin(), v.end()); // 对所有子区间和排序 
	for (int i = 1; i < v.size(); i++)
		ret = min(ret, abs(v[i] - v[i - 1])); // 找到相邻两个子区间和最小值 
	cout << ret << endl; 
	return 0;
}
